package sz.com.battleship.game;

import sz.com.battleship.R;
import android.app.Activity;
import android.content.Intent;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.view.View.OnClickListener;

public class MenuMulti extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
	Button SButton = null;
	Button CButton = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.multiplayer_menu);
        SButton = (Button) findViewById(R.id.buttonServer);
        SButton.setOnClickListener(this);
        CButton = (Button) findViewById(R.id.buttonClient);
        CButton.setOnClickListener(this);   
    }
    
    @Override
    public void onClick(View v)
    {
    	if(v.getId() == R.id.buttonServer)
    	{
    		Intent myIntent = new Intent(v.getContext(), GameScreen.class);
    		WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
            WifiInfo wifiInfo = wifiManager.getConnectionInfo();
            int ipAddress = wifiInfo.getIpAddress();
            String serverIpAddresse = String.format("%d.%d.%d.%d",
            		(ipAddress & 0xff),
            		(ipAddress >> 8 & 0xff),
            		(ipAddress >> 16 & 0xff),
            		(ipAddress >> 24 & 0xff));
            
    		myIntent.putExtra("IP", serverIpAddresse);
    		myIntent.putExtra("Server", true);
            startActivityForResult(myIntent, 0);
    	}
    	else if (v.getId() == R.id.buttonClient)
    	{
    		Intent myIntent = new Intent(v.getContext(), Client.class);
            startActivityForResult(myIntent, 0);
    	}
    }
}